In [1]:
import matplotlib
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sn
%matplotlib inline
import pandas_datareader.data as web
from datetime import datetime
In [2]:
symbol = ['RUB=X', 'BZ=F']
In [3]:
brent = pd.read_csv("brent.csv")
brent['Дата'] = pd.to_datetime(brent['Дата'])
brent = brent.sort_values('Дата')
brent.head()
Out[3]:
In [4]:
rub = pd.read_csv("USD_RUB.csv")
rub['Дата'] = pd.to_datetime(rub['Дата'])
rub = rub.sort_values('Дата')
rub.head()
Out[4]:
In [5]:
brent['Изм. %'] = brent['Изм. %'].str.replace(',', '.')
In [6]:
brent['Изм. %'] = brent['Изм. %'].astype(float)
In [7]:
print ('Brent сумма %: ' , brent['Изм. %'].sum())
In [8]:
rub['Изм. %'] = rub['Изм. %'].str.replace(',', '.')
rub['Изм. %'] = rub['Изм. %'].astype(float)
print ('USD/RUB сумма %: ' , rub['Изм. %'].sum())
In [9]:
brent['Цена'] = brent['Цена'].str.replace(',', '.')
brent['Цена'] = brent['Цена'].astype(float)
rub['Цена'] = rub['Цена'].str.replace(',', '.')
rub['Цена'] = rub['Цена'].astype(float)
In [10]:
brent = brent.reset_index()
rub = rub.reset_index()
In [11]:
plt.plot(rub['Дата'], rub['Цена'])
plt.plot(brent['Дата'], brent['Цена'])
plt.xlabel('Дата')
plt.ylabel('Цена')
plt.legend(['Brend', 'USD/RUB'])
plt.show()
In [12]:
plt.plot(rub['Дата'], rub['Изм. %'])
plt.plot(brent['Дата'], brent['Изм. %'])
plt.xlabel('Дата')
plt.ylabel('% изминение')
plt.legend(['Brend', 'USD/RUB'])
plt.show()
In [13]:
plt.plot(rub['Дата'], rub['Изм. %'])
Out[13]:
In [14]:
plt.plot(brent['Дата'], brent['Изм. %'])
Out[14]:
In [15]:
data = pd.DataFrame() #creates a new dataframe that's empty
rub['usd/rub'] = rub['Цена']
brent['brent'] = brent['Цена']
data = pd.concat([rub.set_index('Дата'),brent.set_index('Дата')], axis=1, join='inner').reset_index()
In [16]:
data.head()
Out[16]:
In [17]:
data[['usd/rub', 'brent']].corr()
Out[17]:
In [18]:
print ('Корреляция за 1 год :', data[['usd/rub', 'brent']].corr().brent[0])
In [19]:
print ('Корреляция за полгода :', data[data['Дата'] < '2016-07-01'][['usd/rub', 'brent']].corr().brent[0])
In [20]:
print ('Корреляция за 3 месяца :', data[data['Дата'] < '2016-04-01'][['usd/rub', 'brent']].corr().brent[0])
In [29]:
rub = pd.read_csv("usd2.csv", delimiter=';')
rub.head()
Out[29]:
In [37]:
rub.dtypes
Out[37]:
In [36]:
rub['Дата'] = pd.to_datetime(rub['<DATE>'])
In [38]:
rub.head()
Out[38]:
In [ ]: